%% Functions to plot intervals (given fixed order)

function fig = plot_intervals_fixord(hat_vartheta, bar_tau, predict_se, order, xtick, ytick)
    
    % Initialization
    N = length(bar_tau);

    % Calculate the recentered intervals
    re_lower_bounds = bar_tau - hat_vartheta - 1.282 * predict_se;
    re_upper_bounds = bar_tau - hat_vartheta + 1.282 * predict_se;
    
    % Sort intervals based on given order
    re_lower_bounds = re_lower_bounds(order);
    re_upper_bounds = re_upper_bounds(order);

    fig = figure;
    set(fig, 'Units', 'inches', 'Position', [1 1 5.833 4.373]);
    hold on;
    
    % Loop through each interval and plot bars, highlighting specified indices
    for i = 1:N
        % Plot regular bar with pink semi-transparency
        rectangle('Position', [i - 0.4, re_lower_bounds(i), 0.8, re_upper_bounds(i) - re_lower_bounds(i)], ...
                  'FaceColor', [1, 0.6, 0.6, 0.5], 'EdgeColor', 'none'); % Pink
    end
    
    yline(0, 'k--', 'LineWidth', 1);
    yticks(ytick);
    ylim([ytick(1), ytick(end)]);
    xticks(xtick);
    xlim([xtick(1), xtick(end)]);
    set(gca, 'FontSize', 18);
   
    hold off;

end
